package com.lightdz.tshirtdz.controller;

import com.lightdz.tshirtdz.bll.ShoppingCarBll;
import com.lightdz.tshirtdz.model.Enum.SortTypeEnum;
import com.lightdz.tshirtdz.model.api.ApiReceiveAddr;
import com.lightdz.tshirtdz.model.api.ApiResponse;
import com.lightdz.tshirtdz.model.api.ApiShoppingCar;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ Description：购物车
 * @ Author     ：zbl
 * @ Date       ：Created in 16:13 09/08/2018
 * @ Modified By：
 */

@RestController
@RequestMapping(value = "/shoppingcar")
public class ShoppingCarController {

    @Autowired
    ShoppingCarBll shoppingCarBll;

    /**
     * 获取我的购物车的商品列表
     */
    @GetMapping(value = "/getmyshoppingcar")
    public ApiResponse<List<ApiShoppingCar>> getMyShoppingCar(String wxId, int pageSize, int pageNo, SortTypeEnum sortType) {
        return shoppingCarBll.getMyShoppingCar(wxId, pageSize, pageNo, sortType);
    }

    /**
     * 添加到我的购物车
     */
    @GetMapping(value = "/addshoppingcar")
    public ApiResponse<Boolean> addShoppingCar(String wxId, String pSize, int pCount, String pColor, long pid) {
        return shoppingCarBll.addShopingCar(wxId, pSize, pCount, pColor, pid);
    }

    /**
     * 编辑我的购物车
     */
    @GetMapping(value = "/editshoppingcar")
    public ApiResponse<Boolean> editShoppingCar(String wxId, long pid, int pCount, boolean delete) {
        if (delete)
            return shoppingCarBll.deleteShoppingCar(wxId, pid);
        else
            return shoppingCarBll.updateShoppingCar(wxId, pid, pCount);
    }
}
